package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.panshi.entity.SysUserRoleT;
import com.panshi.service.impl.SysUserRoleTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户角色关系表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-13
 */
@RestController
public class SysUserRoleTController {

    @Autowired
    private SysUserRoleTServiceImpl sysUserRoleTService;

    //获得用户角色
    @ApiOperation("管理员ID获得 角色ID")
    @GetMapping("/sys-user-role-t/userrole/{adminId}")
    public SysUserRoleT userRole(@PathVariable int adminId){
        return sysUserRoleTService.getOne(new QueryWrapper<SysUserRoleT>().eq("admin_id",adminId));
    }


    @ApiOperation("管理员添加角色关系")
    @PostMapping("/sys-user-role-t/sysUserAddRole")
    public Boolean sysUserAddRole(@RequestBody SysUserRoleT sysUserRoleT){
        return sysUserRoleTService.save(sysUserRoleT);
    }

    @ApiOperation("删除管理员角色关系 ")
    @PostMapping("/sys-user-role-t/sysUserDelRole")
    public Boolean sysUserDelRole(@RequestBody SysUserRoleT sysUserRoleT){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("admin_id",sysUserRoleT.getAdminId());
        wrapper.eq("role_id",sysUserRoleT.getRoleId());

        return sysUserRoleTService.remove(wrapper);
    }
}

